#include "userMain.h"
#include "userShortLongKey.h"

void userShotrLongKeyFunc(const struct SeLongKeyElement Element,struct SeLongKeyVariate *Variate)
{
	switch (Variate->ProcessStep)
    {   
        //step1: detect keypad if pressed
        case 1:
            //keypad pressed, jump step2
            if(*(Variate->KeyValueNow) == Element.PressValue)
            {
                Variate->ProcessStep = 2;
                *(Variate->KeyTik) = 0;
            }
            //no keypad pressed, stay step1
            else
            {
                Variate->ProcessStep = 1;
            }
            break;
        //step2: keypad already pressed, judge if shortpress or longpress
        case 2:
            //if keypad stay pressed
            if(*(Variate->KeyValueNow) == Element.PressValue)
            {
                if(*(Variate->KeyTik) >= Element.LongPressTimeDefine)
                {
                	//call long press function
                    (*(Element.LongFun2))();
                    Variate->ProcessStep = 3;
                }
                else
                {
                    Variate->ProcessStep = 2;
                }
            }
            else	//call short press function
            {
                (*(Element.SeFun1))();
                Variate->ProcessStep = 1;
            }
            break;
        //  
        case 3:  //long pressed ,wait keypad released
            if(*(Variate->KeyValueNow) == Element.ReleaseValue)
            {// keypad released, back to step1
                Variate->ProcessStep = 1;
            }
            else //keypad not released, stay step3
            {
                Variate->ProcessStep = 3;
            }
            break;
        default:
            Variate->ProcessStep = 1;
            break;
    }    
}

/********************END OF FILE************************************/
